#ifndef __ADS7042_PORT_H
#define __ADS7042_PORT_H
#include <stdint.h>
#include <string.h>
#include "nrf_drv_common.h"
#include "nrf_drv_spi.h"
#include "app_util_platform.h"
#include "app_error.h"
#include "nrf_gpio.h"
#include "boards.h"
#include "nrf_delay.h"
#include "ads7042_port.h"

/******************************************************************************
** SPI_FLASH
********************************************************************************/
typedef enum
{
    RET_SUCCESS = 0,
    RET_FlashRead_ERROR,
    RET_WriteCmd_ERROR,
    RET_WaitBusy_ERROR
}SpiRetValueType;


/*****************************************************************************
** SPI ����
*****************************************************************************/
#define  SPI_INSTANCE   	1 	// SPI  INSTANCE number
#define  SPI1_SS_PIN      13  // CS   PIN
#define  SPI1_SCLK_PIN		15	// SCLK PIN
#define  SPI1_MISO_PIN		14	// MISO PIN
#define  SPI1_MOSI_PIN		23	// MOSI PIN



#define    SPIFLASH_CMD_LENGTH        0x03
#define    SPIFLASH_WRITE_BUSYBIT     0X01
#define    SPIFlash_ReadData_CMD      0x03
#define    SPIFlash_WriteEnable_CMD   0x06
#define    SPIFlash_WriteDisable_CMD  0x04
#define    SPIFlash_PageProgram_CMD   0x02
#define    SPIFlash_WriteSR_CMD       0x01
#define    SPIFlash_ReadSR_CMD        0x05
#define    SPIFlash_SecErase_CMD      0x20
#define    SPIFlash_BlockErase_CMD    0xD8
#define    SPIFlash_PAGEBYTE_LENGTH   256
#define    SPIFlash_SECBYTE_LENGTH   (1024*4)
#define    FLASH_BLOCK_NUMBLE         7
#define    FLASH_PAGE_NUMBLE          8



/*******************************************************************************
**
*******************************************************************************/
void spi_init(void);
void SPI_Disable(void);
void spi_event_handler(nrf_drv_spi_evt_t const * p_event,
                       void *                    p_context);
uint16_t ADS7042_Readsingle(void);
float ADS7042_Conv(uint16_t adc_value, float vref);
void SPI_ReadWriteData(uint8_t *pWriteData, uint8_t *pReadData, uint8_t writeDataLen);
void Process_Sine_Wave(void);
void Get_Wave_state(void);

#endif
